//
//  TopSpecialDetailListTableViewController.m
//  WisdomZhuHai
//
//  Created by BABLE on 15/4/24.
//  Copyright (c) 2015年 wyd. All rights reserved.
//

#import "TopSpecialDetailListTableViewController.h"
#import "Common.h"
#import "ProtocolDefine.h"

//设定CELL高度
const float TOPIMAGECELL_HEIGHT = 110;//顶部图片高
const float TITLECELL_HEIGHT = 22;//标题高
const float OKCOMMENDCELL_HEIGHT = 85;//专题列表高

@interface TopSpecialDetailListTableViewController ()
//专题列表接口、图片和标题CELL的构建、专题列表CELL与commoncell.xib的关联及设置、整个tableview的填充、在专题详情页面中的适配
@property (strong,nonatomic)TopSpecialDetailListTableViewController *listView;

@end

@implementation TopSpecialDetailListTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"TopSpecialDetailViewControlleViewController" owner:self options:nil];
    self.listView = (UITableView *)[array[0] viewWithTag:980001];
    [self.view addSubview:self.listView];

//    self.tableView.frame = CGRectMake(0, 20, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 70);
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 0;
}
//if(index == 0){
//    
//}else if (index == 1){
//    
//}else{
//}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;

    if(indexPath.row == 0){
//        UIImageView *topImage = [[UIImageView alloc] initWithFrame:(0, 0, self.view.bounds.size.width,TOPIMAGECELL_HEIGHT)];
        UIImageView *topImage = [[UIImageView alloc] initWithFrame:cell.bounds];
//        NSString *imgUrl = [Common valueForKey:P_NPHOTO dic:cellDic];
        NSString *imgUrl = @"http://img0.imgtn.bdimg.com/it/u=1422648105,2947397479&fm=21&gp=0.jpg";
        [topImage setImageWithURL:[Common getFullDownloadPathByRelativePath:imgUrl]];
        [cell addSubview:topImage];
    }
    else if(indexPath.row == 1){
//        UIView *titleBackgroundView = [[UIView alloc] initWithFrame:cell.bounds];
//        titleBackgroundView.backgroundColor = [Common colorWithRGB:0xf9f9f9];
////        CGFloat lableWidth = cell.bounds.size.width;
////        UILabel *specialGroupTitle = [[UILabel alloc] initWithFrame:(0,2,lableWidth,TITLECELL_HEIGHT-2)];
//        UILabel *specialGroupTitle = [[UILabel alloc] init];
////        specialGroupTitle.text = [Common valueForKey:P_IS_TOPIC dic:self.superData];
//        specialGroupTitle.text = @"测试";
//        [titleBackgroundView addSubview:specialGroupTitle];
//        [cell addSubview:titleBackgroundView];
        cell.textLabel.text = @"测试";
    }
//    else{
//        cell = [tableView dequeueReusableCellWithIdentifier:@"CommonCell"];
//        // Configure the cell...
//        if(cell == nil)
//        {
//            cell = [[NSBundle mainBundle] loadNibNamed:@"CommonCell"  owner:self options:nil][0];
//        }
//        
//        [self specailListCellSetup:cell index:indexPath.row];
//    }
    NSAssert(cell != nil, @"specialMessageViewController cell is nil");
    return cell;
}

#pragma mark - cell
- (void)specailListCellSetup:(UITableViewCell*)cell index:(NSInteger)index;
{
    cell.contentView.backgroundColor = [Common colorWithRGB:0xf9f9f9];
    if (self.newsList.count <= 0) {
        return;
    }

    NSDictionary *cellDic = self.newsList[index];
    NSString *imgUrl = [Common valueForKey:P_NPHOTO dic:cellDic];
    NSString *title = [Common valueForKey:P_NRTITLE dic:cellDic];
    NSArray *tagsList = [Common valueForKey:P_TAGS dic:cellDic];
    NSString *source_name = [Common valueForKey:P_V2_SOURCE_NAME dic:cellDic];
    NSString *comment_cnt = [Common valueForKey:P_V2_COMMENT_CNT dic:cellDic];
    NSString *date = [Common valueForKey:P_UPDATED_TIME dic:cellDic];
    UIImageView *image = (UIImageView*)[cell viewWithTag:1001];
    [image setImageWithURL:[Common getFullDownloadPathByRelativePath:imgUrl]];
    UIImageView *okImage = (UIImageView*)[cell viewWithTag:1007];
    okImage.hidden = YES;
    
    UILabel *titleLab = (UILabel*)[cell viewWithTag:1002];
    [titleLab setNumberOfLines:2];
    titleLab.text = title;
    [titleLab sizeToFit];
    CGRect frame = titleLab.frame;
    frame.size.width = 216;
    titleLab.frame = frame;
    
    [self tagSetup:tagsList titleLabHeight:frame.size.height cell:cell];
    UILabel *price = (UILabel*)[cell viewWithTag:1005];
    [price removeFromSuperview];
    UIImageView *districtNameImg = (UIImageView*)[cell viewWithTag:2001];
    [districtNameImg removeFromSuperview];
    UILabel *districtNameLab = (UILabel*)[cell viewWithTag:2002];
    districtNameLab.text = [NSString stringWithFormat:@"%@ %@", [date componentsSeparatedByString:@" "][0],source_name ];
    UIImageView* goodImg = (UIImageView*)[cell viewWithTag:2003];
    [goodImg removeFromSuperview];
    UILabel* CommontLab = (UILabel*)[cell viewWithTag:2006];
    CommontLab.text = comment_cnt;


}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{   //CELL尺寸判断器

        if(indexPath.row == 0)
        {
            return TOPIMAGECELL_HEIGHT;
        }
        else if(indexPath.row == 1)
        {
            //专题标题
            return TITLECELL_HEIGHT;
        }
        else
        {
            return OKCOMMENDCELL_HEIGHT;
        }
        return tableView.rowHeight;
}
//#pragma mark - PullTableViewDelegate
//- (void)pullTableViewDidTriggerRefresh:(PullTableView*)pullTableView
//{
//    //下拉刷新
//    if(self.specialDelegate && [self.specialDelegate respondsToSelector:@selector(specialDetailTableViewDidTriggerRefresh:)])
//    {
//        [self.specialDelegate specialDetailTableViewDidTriggerRefresh:self];
//    }
//}
/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
